package com.yang.springcloudalibaba.controller;

import com.yang.springcloud.pojo.Student;
import com.yang.springcloudalibaba.service.StudentClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class StudentConsumerConterller {

    @Autowired
    private StudentClientService sc;

    @PostMapping("/consumer/student/insert")
    public Map<String, Object> addStudent(Student s){
        System.out.println(s.getId()+ " " + s.getName() + " " + s.getBirth() + " " + s.getSex());
        return this.sc.addStudent(s);
    }

    @PostMapping("/consumer/student/delete")
    public Map<String, Object> deleteStudent(String name){
        System.out.println(name);
        return this.sc.delereStudent(name);

    }

    @PostMapping("/consumer/student/update")
    public Map<String, Object> updateStudent(Student s){
        return this.sc.updateStudent(s);
    }

    @GetMapping("/consumer/student/query")
    //@SentinelResource(value = "queryStudent", fallback = "fallback", blockHandler = "handler")  //fallback负责业务异常，blockHandler只负责sentinel控制台违规
    public List<Student> queryStudent(String name){
        return this.sc.queryAll();
    }

//    public String fallback(){
//        return "fallback";
//    }
//
//    public String handler(){
//        return "handler";
//    }
}
